From: Seth Michael Larson Date: Tue, 20 Jan 2026 20:45:42 +0000 (-0600) Subject: gh-143921: Reject control characters in IMAP commands X-Git-Tag: archive/raspbian/3.9.2-1+rpi1+deb11u6^2^2~5 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com//%22mailto:bartha.m.judit%40gmail.com/%22/%22http:/www.example.com/%22mailto:bartha.m.judit%40gmail.com/%22?a=commitdiff_plain;h=d2f5a3b1cd319fb2933ddb0709455fcd67261cee;p=python3.9.git gh-143921: Reject control characters in IMAP commands Origin: upstream, https://github.com/python/cpython/commit/6262704b134db2a4ba12e85ecfbd968534f28b45 Gbp-Pq: Name CVE-2025-15366.patch --- diff --git a/Lib/imaplib.py b/Lib/imaplib.py index d9720f2..3eff314 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -129,7 +129,7 @@ Untagged_status = re.compile( # We compile these in _mode_xxx. _Literal = br'.*{(?P\d+)}$' _Untagged_status = br'\* (?P\d+) (?P[A-Z-]+)( (?P.*))?' - +_control_chars = re.compile(b'[\x00-\x1F\x7F]') class IMAP4: @@ -985,6 +985,8 @@ class IMAP4: if arg is None: continue if isinstance(arg, str): arg = bytes(arg, self._encoding) + if _control_chars.search(arg): + raise ValueError("Control characters not allowed in commands") data = data + b' ' + arg literal = self.literal diff --git a/Lib/test/test_imaplib.py b/Lib/test/test_imaplib.py index 914a75a..fc918af 100644 --- a/Lib/test/test_imaplib.py +++ b/Lib/test/test_imaplib.py @@ -536,6 +536,12 @@ class NewIMAPTestsMixin(): self.assertEqual(data[0], b'Returned to authenticated state. (Success)') self.assertEqual(client.state, 'AUTH') + def test_control_characters(self): + client, _ = self._setup(SimpleIMAPHandler) + for c0 in support.control_characters_c0(): + with self.assertRaises(ValueError): + client.login(f'user{c0}', 'pass') + class NewIMAPTests(NewIMAPTestsMixin, unittest.TestCase): imap_class = imaplib.IMAP4 diff --git a/Misc/NEWS.d/next/Security/2026-01-16-11-41-06.gh-issue-143921.AeCOor.rst b/Misc/NEWS.d/next/Security/2026-01-16-11-41-06.gh-issue-143921.AeCOor.rst new file mode 100644 index 0000000..4e13fe9 --- /dev/null +++ b/Misc/NEWS.d/next/Security/2026-01-16-11-41-06.gh-issue-143921.AeCOor.rst @@ -0,0 +1 @@ +Reject control characters in IMAP commands.